package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Region;
import cn.wolfcode.trip.base.mapper.RegionMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IRegionService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RegionServiceImpl implements IRegionService {
  @Autowired
  private RegionMapper regionMapper;

    @Override
    public void save(Region region) {

    }

    @Override
    public List<Region> selectByParentId(Long parentId) {
        return regionMapper.selectByParentId(parentId);
    }


    @Override
    public PageInfo<?> query(QueryObject qo) {

        return null;
    }

    @Override
    public void update(Region region) {

    }

  public void saveOrUpdate(Region entity) {
    if (entity.getId() == null) {
      regionMapper.insert(entity);
    } else {
      regionMapper.updateByPrimaryKey(entity);
    }
  }

  @Override
  public List<Region> list(Integer state) {
    return regionMapper.selectAll(state);
  }
}
